<?php

namespace App\Containers\AppSection\Confirmation\Tasks;

use App\Containers\AppSection\Confirmation\Data\Repositories\ConfirmationRepository;
use App\Ship\Exceptions\DeleteResourceFailedException;
use App\Ship\Parents\Tasks\Task;
use Exception;

class DeleteAllConfirmsByValueTask extends Task
{
    protected ConfirmationRepository $repository;

    public function __construct(ConfirmationRepository $repository)
    {
        $this->repository = $repository;
        // ..
    }

    public function run(string $value, string $requestType, string $confirmType): int
    {
        try {
            return $this->repository->deleteWhere([
                ['value', '=', $value],
                ['request_type', '=', $requestType],
                ['confirm_type', '=', $confirmType],
            ]);
        } catch (Exception $exception) {
            throw new DeleteResourceFailedException();
        }


    }
}
